
#include <core.h>
#include <cpu.h>
#include <mem.h>
#include <dev.h>

/* ------------------------------------------------------------------------- */

uint32 size_mask_table[] = { 0x000000ff, 0x0000ffff, 0x00ffffff, 0xffffffff };

/* ------------------------------------------------------------------------- */

void power_on(void)
{
	FILE *fp = fopen("debug\\rom\\mcpx.bin", "rb");
	uint8 *buf = malloc(MCPX_SIZE);
	uint8 *buf2;

	fread(buf, 1, MCPX_SIZE, fp);
	fclose(fp);
	mcpx_init(buf);

	fp = fopen("debug\\rom\\3944.bin", "rb");
	buf2 = malloc(ROM_FIX);
	fread(buf2, 1, ROM_FIX, fp);
	fclose(fp);
	rom_init(buf2);

	free(buf2);
	free(buf);

	ram_init();
	dev_init();
	cpu_reset();
}

void power_off(void)
{

}

#ifndef NDEBUG
#include <stdarg.h>
#include <Windows.h>
void write_log(const char *fmt, ...)
{
	va_list arg;
	char str[1024];

	va_start(arg, fmt);
	strcat(str + vsprintf(str, fmt, arg), "\n");
	va_end(arg);

	OutputDebugStringA(str);
}
#endif

/* ------------------------------------------------------------------------- */
